import {WeaLocaleProvider} from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;
const provs = [11, 12, 13, 14, 15, 21, 22, 23, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 50, 51, 52, 53, 54, 61, 62, 63, 64, 65, 71, 81, 82]
export default {
    custom: {
      validate: (com) => {
        const { value, config:{ IDcardVerification } } = com;

        if(!value) return true;

        if(parseInt(IDcardVerification)){
        const regExp = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|30|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/;
        const startStr = parseInt(value.substring(0,2));

        if(provs.indexOf(startStr) === -1) return false;

        if(!regExp.test(value)) return false;
        }
        return true;
      },
      error: () => `${getLabel('511370' ,'请输入正确的身份证号')}`
    }
  };